<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('支付订单列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>订单渠道：</label>
                            <select name="channel" th:with="type=${@dict.getType('sys_min_user_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>支付状态：</label>
                            <select name="tradeState" th:with="type=${@dict.getType('sys_order_trade_state')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>订单类型：</label>
                            <select name="orderType" th:with="type=${@dict.getType('sys_order_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>支付类型：</label>
                            <select name="payType" th:with="type=${@dict.getType('sys_order_pay_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 105px;">关键字查询字段：</label>
                            <select name="fields">
                                <option value="appUserId" selected>用户ID</option>
                                <option value="outOrderNo">商户订单号</option>
                                <option value="transactionId">交易单号</option>
                                <option value="partnerFullName">直属合作商</option>
                                <option value="merchantFullName">直属商户</option>
                                <option value="storeName">直属门店</option>
                            </select>
                            <input type="text" name="keywords"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:order:add">-->
            <!--<i class="fa fa-plus"></i> 添加-->
            <!--</a>-->
            <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()"-->
            <!--shiro:hasPermission="system:order:edit">-->
            <!--<i class="fa fa-edit"></i> 修改-->
            <!--</a>-->
            <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"-->
            <!--shiro:hasPermission="system:order:remove">-->
            <!--<i class="fa fa-remove"></i> 删除-->
            <!--</a>-->
            <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:order:export">-->
            <!--<i class="fa fa-download"></i> 导出-->
            <!--</a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:order:edit')}]];

    var refundFlag = [[${@permission.hasPermi('system:order:refundMoney')}]];
    var refundDepositFlag = [[${@permission.hasPermi('system:order:refundDeposit')}]];

    var removeFlag = [[${@permission.hasPermi('system:order:remove')}]];
    var channelDatas = [[${@dict.getType('sys_min_user_type')}]];
    var tradeStateDatas = [[${@dict.getType('sys_order_trade_state')}]];
    var orderTypeDatas = [[${@dict.getType('sys_order_type')}]];
    var payTypeDatas = [[${@dict.getType('sys_order_pay_type')}]];
    var prefix = ctx + "system/order";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "支付订单",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'outOrderNo',
                    title: '商户订单号'
                },
                {
                    field: 'transactionId',
                    title: '交易单号'
                },
                {
                    field: 'createdTime',
                    title: '创建订单时间'
                },
                {
                    field: 'channel',
                    title: '订单渠道',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(channelDatas, value);
                    }
                },
                {
                    field: 'appUserId',
                    title: '用户昵称(用户ID)',
                    formatter: function (value, row, index) {
                        return row.nickName + "&nbsp;(" + value + ")";
                    }
                },
                {
                    field: 'orderType',
                    title: '订单类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderTypeDatas, value);
                    }
                },
                {
                    field: 'partnerFullName',
                    title: '直属合作商'
                },
                {
                    field: 'merchantFullName',
                    title: '直属商户'
                },
                {
                    field: 'storeName',
                    title: '门店名称'
                },
                {
                    field: 'totalFee',
                    title: '金额'
                },
                {
                    field: 'payType',
                    title: '支付类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(payTypeDatas, value);
                    }
                },
                {
                    field: 'tradeState',
                    title: '支付状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(tradeStateDatas, value);
                    }
                },
                {
                    field: 'merchantId',
                    title: '直属商户ID'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];

                        if (row.tradeState == 1) {
                            /**
                             * 1 押金
                             * 2 机柜租赁费用
                             * 3 线租借费用
                             */
                            if (row.orderType == 1) {
                                actions.push('<a class="btn btn-primary btn-xs ' + refundDepositFlag + '" href="javascript:void(0)" onclick="refundDeposit(\'' + row.id + '\')"><i class="fa fa-close"></i>退押金</a> ');
                            } else {
                                /**
                                 *  支付状态
                                 0—未支付
                                 1—支付成功
                                 2—转入退款
                                 3—退款成功
                                 4—退款异常
                                 5—退款关闭
                                 6—已关闭
                                 7--支付失败(其他原因，如银行返回失败)
                                 */
                                // 支付成功，可退款
                                actions.push('<a class="btn btn-success btn-xs ' + refundFlag + '" href="javascript:void(0)" onclick="refundMoney(\'' + row.id + '\')"><i class="fa fa-times"></i>退款</a> ');
                            }
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    // 退款操作
    function refundMoney(id) {
        var url = prefix + "/refundMoney/" + id;
        $.modal.open("订单退款", url, 800, 460);
    }

    // 退押金
    function refundDeposit(id) {
        var url = prefix + "/refundDeposit";
        var data = {
            "id": id,
        };
        $.modal.confirm("确认退押金？", function () {
            $.operate.submit(url, "post", "json", data);
        });
    }

</script>
</body>
</html>